// JavaScript Document
var total=0; //要轮换的图片总数
var index=0; //当前显示的图片的索引
var time=null;

$(function(){
	total=$("#navy_show_img li").length;  //获取图片的总数
	
	//去除超出的图片部分
	$("#navy_show_imgsmall img").addClass("navy_out");
	
	
	//显示鼠标的箭头图像
	$("#navy_show_img").mousemove(function(e){
		var num=e.offsetX;
		if(num<200){
			$(this).css("cursor","url(images/left.png),default");
			clearInterval(time);
			time=null;
		}else if(num>450){
			$(this).css("cursor","url(images/right.png),default");
			clearInterval(time);
			time=null;
		}else{
			$(this).css("cursor","default");
			if(time==null){
				time=window.setInterval("showPicAuto()",1000);
			}
		}
	});
	
	//小图像  左移的点击事件
	$("#navy_right").click(function(){
		if(total>8){  //说明至少有2页
			var num=parseInt(index/8)+1;//1,2,3
			
			//求最后一页的页码
			var page=total%8==0?total/8:Math.ceil(total/8);
			
			if(num<page){
				$("#navy_show_imgsmall_view").animate({scrollLeft:592*num},300);
				index=num*8;
				showPic(index);	
			}
		}
	}); 
	$(".fifthchild").click(function(){
		
		$(".navy_show_img_div").css("display","block");
		
		$("#closedPic").css("display","block");
		}
	);
	$("#closedPic").click(function(){
		
		$(".navy_show_img_div").css("display","none");
		$("#closedPic").css("display","none");
		}
	);
	$("#closedPic").mouseover(function(){
		
		
		$("#closedPic").css("cursor","pointer");
		}
	);
	//鼠标移开图片时，
	$("#navy_show_img").mouseout(function(){
		//console.info("aa"); //当点击时，也会触发,why
		clearInterval(time);
		time=null;
		if(time==null){
			time=window.setInterval("showPicAuto()",1000);
		}
	});
	
	
	//大图像的点击箭头
	$("#navy_show_img").click(function(e){
		var num=e.offsetX;
		
		if(num<200){   //说明是要看前面的图片
			if(index<=0){
				return;
			}else{
				if(index!=0  &&  index%8==0){
					$("#navy_show_imgsmall_view").animate({scrollLeft:((index/8-1)*592)},300);	
				}
				var now_index=$("#navy_show_imgsmall img[class='navy_over']").parent().index();
				if(now_index!=index){
					index=now_index;	
				}
				index-=1;
			}	
		}
		else if(num>450){
			if(index>=total-1){  //已经是最后一张
				return;
			}else{
				//避免一次性跳  2 张
				var now_index=$("#navy_show_imgsmall img[class='navy_over']").parent().index();
				if(now_index!=index){
					index=now_index;	
				}
				index+=1;
				if(index!=0  &&  index%8==0){
					$("#navy_show_imgsmall_view").animate({scrollLeft:((index/8)*592)},300);	
				}
			}
		}	
		showPic(index);
	});
	
	//小图像左移的点击事件
	$("#navy_left").click(function(){
		var left=$("#navy_show_imgsmall_view").scrollLeft(); //获取图片的滚动距离
		
		if(left>=592){//说明不是第一页
			$("#navy_show_imgsmall_view").animate({scrollLeft:left-592},300);
			index=(Math.floor(left/592)-1)*8;
			showPic(index);
		}
	});
	
	//小图片上绑定  事件
	$("#navy_show_imgsmall li").unbind();
	$("#navy_show_imgsmall li").bind({
		mouseover:function(){
			clearInterval(time);
			time=null;
			index=$(this).index();
			showPic(index);	
		},
		mouseout:function(){
			clearInterval(time);
			time=null;
			if(time==null){
				time=window.setInterval("showPicAuto()",1000);
			}
		}
	});
	
	//开头启动一次
	if(time==null){
		time=window.setInterval("showPicAuto()",1000);
	}
});

//显示图片和对应的标题及小图片
function showPic(index){
	//大图片
		$("#navy_show_img li").css("display","none").eq(index).css("display","block");
		
	
	
	//小图片
		$("#navy_show_imgsmall img").attr("class","navy_out").eq(index).attr("class","navy_over");
}

//图片自动  变换的方法
function showPicAuto(){
	//console.info(arguments+"长度");
	if(arguments.length>0){//说明要显示指定的图片
		index=arguments[0];	
	}else{
		index=index%total;	
	}	
	
	if(index==0){
		$("#navy_show_imgsmall_view").animate({scrollLeft:0},300);
	}
	
	if(index!=0 &&  index%8==0){  //说明一页结束ule
		$("#navy_show_imgsmall_view").animate({scrollLeft:(index/8*592)},300);
	}
	showPic(index);
	index++;
}




/*导航栏菜单功能*/
function jddhShow(){
	switch (true) {		
		default :
			$("#nav li").attr("class","");
			$("#nav li").eq(4).attr("class","nav_lishw");
			$(".nav_lishw .v a").attr("class","sele");
			$(".nav_lishw .kind_menu").show();
	} 
	
	$("#nav li").hover(
		function(){
			clearTimeout(setTimeout("0")-1);
			$("#nav .kind_menu").hide(); 
			$("#nav li .v .sele").attr("class","shutAhover");
			$(this).attr("id","nav_hover")
			$("#nav_hover .v a").attr("class","sele");
			$("#nav_hover .kind_menu").show(); 
		},
		function(){
			if($(this).attr("class") != "nav_lishw"){
				$("#nav_hover .v .sele").attr("class","");
				$("#nav_hover .kind_menu").hide(); 
			}
			$(this).attr("id","")
			$("#nav li .v .shutAhover").attr("class","sele");
			setTimeout(function(){
				$(".nav_lishw .kind_menu").show();
				$(".nav_lishw .v a").attr("class","sele");
			},50); 
		}
	);
}

//头部的显示与隐藏
function head_show(){
	var tcPhone=$("#tcPhone");
	var tcPhone_info=$("#tcPhone_info");
	var servicePhone=$("#servicePhone");
	var servicePhone_info=$("#servicePhone_info");
	var topJoinTc=$("#topJoinTc");
	var topJoinTc_info=$("#topJoinTc_info");
	
	tcPhone.mouseover(function(e) {
        tcPhone_info.css("display","block");
		tcPhone.css("background","#ccc");
		$("#tcPhone a").css("color","#FF7800");
		$("#tcPhone img").attr("src","images/arrow.png");
    });
	tcPhone.mouseout(function(e) {
        tcPhone_info.css("display","none");
		tcPhone.css("background","");
		$("#tcPhone a").css("color","");
		$("#tcPhone img").attr("src","images/arrow2.png");
    });
	servicePhone.mouseover(function(e) {
        servicePhone_info.css("display","block");
		servicePhone.css("background","#ccc");
		$(".servicePhone_a").css("color","#FF7800");
		$("#servicePhone img").attr("src","images/arrow.png");
    });
	servicePhone.mouseout(function(e) {
        servicePhone_info.css("display","none");
		servicePhone.css("background","");
		$(".servicePhone_a").css("color","");
		$("#servicePhone img").attr("src","images/arrow2.png");
    });
	topJoinTc.mouseover(function(e) {
        topJoinTc_info.css("display","block");
		topJoinTc.css("background","#ccc");
		$(".topJoinTc_a").css("color","#FF7800");
		$("#topJoinTc img").attr("src","images/arrow.png");
    });
	topJoinTc.mouseout(function(e) {
        topJoinTc_info.css("display","none");
		topJoinTc.css("background","");
		$(".topJoinTc_a").css("color","");
		$("#topJoinTc img").attr("src","images/arrow2.png");
    });	
}

window.onload=function(){
	jddhShow(); //导航栏下拉信息
	head_show();
	
	var jd_pic_main=document.getElementsByClassName("jd_pic_main").item(0).getElementsByTagName("img");
	var imgs=document.getElementsByClassName("albums").item(0).getElementsByTagName("img");
	for(var i=0;i<5;i++){
		imgs[i].onmouseover=function(){
			for(var j=0;j<5;j++){
				imgs[j].style.borderColor="#0F0";
			}
			this.style.borderColor="#F00";
			jd_pic_main.item(0).src=this.src;
		}
	}
	
};
function checkInfos(){
	var str1=$.trim($("#st").val());
	var str2=$.trim($("#over").val());
	var map = new BMap.Map("l-map");
	map.centerAndZoom(new BMap.Point(112.70421, 26.87821), 12);

	 var transit = new BMap.DrivingRoute(map, {
		renderOptions: {
			map: map,
			panel: "r-result",
			enableDragging : true //起终点可进行拖拽
		},  
	});
	transit.search(str1,str2);
}

//发表评论
function fabiao(){
	var contents=""; //评论内容
	var info=$(".register").html(); 
	var strComments="";
	if(info=="注册"){   //说明没有用户登录
		alert("请先登录");
		return;
	}else if(info=="退出"){ //说明已经有用户登录
		var userName=$(".login").html(); //获取用户名
		var jdNames=$(".jdName").html(); //获取当前景点名
		 $.post("jdInfoServlet?t="+new Date(),{op:"JdCommentPublish",userName:userName,jdNames:jdNames},function(data){
			 $.each(data.rows,function(index,item){
				 if(item=="0"){  //如果返回的是0，则说明该用户没有预订本景点
					 alert("您还未预订此景点，不能进行评论...");
					 $("#contents").val("");
					 return;
				 }else if(item.STATUS=="1"){  //如果返回的结果状态为1
					 var temp=$("textarea").val();
					 $.post("jdInfoServlet?t="+new Date(),{op:"AddJdComment",temp:temp,userName:userName,jdNames:jdNames},function(data){
						 $.each(data.rows,function(index,item){
							 if(item){
								 $.post("jdInfoServlet?t="+new Date(),{op:"JdCommentLeaps"},function(datass){
									 $.each(datass.rows,function(index,items){
								 			if(items.PHOTO==null){
								 				items.PHOTO="images/mrhead1.png";
								 			}
					 						strComments+='<tr height="120px" width=100% align="center"><td width=20%><ul>';
					 						strComments+='<li><img src="'+items.PHOTO+'" height="80px" class="jdpl_src"/></li>';
					 						strComments+='<li><p class="jdpl_user" style="color:red">'+items.UNAME+'</p></li></ul></td>';
					 						strComments+='<td width=80%><ul><li style="width:800px; height:80px;margin-top:10px;"><p align="left" class="jdpl_contents">'+items.CONTENT+'</p></li>';
					    					strComments+='<li style="width:800px; height:20px;"><p align="left" class="jdpl_dates">发表时间：<span style="color:red">'+items.CDATE.substring(0,10)+'</span></p></li></ul></td></tr>';
								    	});
									    Countss=parseInt(Countss)+1;  //评论的总数+1
									    //评论的总页数
									    if((parseInt(Countss))%3==0){  //如果评论总数是每页显示数的整数倍，则总页数为总数/每页显示数
									    	totalss=(parseInt(Countss))/3;
										}else{ //如果不是，则总页数+1
											totalss=parseInt((parseInt(Countss))/3)+1;
										}
									    $("#jdpl_table").html(strComments); //设置内容的分页显示
									    $("#pageNo").html(1);  //默认第1页
									    $("#totalSize").html(Countss); //设置评论总数
									    $("#totalPage").html(totalss); //设置评论的总页数
									    $(".jdCommentsCount").html(Countss); //设置上一条、下一条的评论总数
									    alert("感谢您的评论...");
									    $("#s-dp-b").css("display","block");
									    
									    
									    $("#jd_comment_infos").val(contents);
									    $("#contents").val("");
								 },"json");
							 }else{
								alert("请输入您的评论...");
								return;
							 }
						 });
					 },"json");
				 }
			 }); 
		 },"json");
		 
		}
	
    if((parseInt(Countss))%3==0){  //如果评论总数是每页显示数的整数倍，则总页数为总数/每页显示数
    	totalss=(parseInt(Countss))/3;
	}else{ //如果不是，则总页数+1
		totalss=parseInt((parseInt(Countss))/3)+1;
	}
	
	console.info("总数："+Countss);
	console.info("总页数："+totalss);
}

